<?php
class IndexController extends Controller {
	public function actionIndex() {
		// print_r(Yii::app()->db);
		// $sql = 'SELECT FROM_UNIXTIME(UNIX_TIMESTAMP())';
		// $row = Yii::app()->db->createCommand($sql)->queryAll();
		// $User = User::model()->tableName();
		// $row = User::model()->findAll();
		// print_r($row);
		$sql = 'select * from ' . User::model ()->tableName () . ' ab inner join '.Basic::model ()->tableName ().' ac on(ab.id=ac.id)';
		
		// $sql = 'PRAGMA table_info("' . User::model ()->tableName () . '")';
		//echo $sql;
		$r = Yii::app()->db->createCommand($sql)->queryAll();
		//echo '<BR>a:';
		//print_r(User::model ()->getTableAlias());
		//echo '<BR>b:';
		//print_r(User::model ()->getAlias());
		//echo '<BR>c:';
		//print_r(Basic::model ()->getAlias());
		
		// echo 'IndexController.actionIndex';
		$model = Category::model ()->findAll ();
		// Yii::log('防止Cookie攻击', CLogger::LEVEL_ERROR, 'application.controller.index');
		// print_r($model);
		foreach($model as $key=>$row){
			//echo '<BR>'.$key.':<BR>';
			//print_r($row);
			//print_r($row->attributes);
			//print_r($row->getTableAlias());
			//echo '<BR>df:'.$row->getTableAlias();
		}
		
		$User = new User();
		$User->dropDownList('sex');
		
		$this->render('index', array());
	}
	
	public function a(){
		$pageSize = Yii::app()->request->getParam('pageSize');
		$currentPage = Yii::app()->request->getParam('currentPage');
		$name = Yii::app()->request->getParam('name');
		if (empty($pageSize)) $pageSize = 10;
		if (empty($currentPage)) $currentPage = 0;
		$criteria = new CDbCriteria ();
		//$criteria->order = 'id desc';
		// print_r(get_declared_classes());
		
		// var_dump($name);
		if (class_exists($name)) {
			$name = new $name();
			$primaryKey = $name->tableSchema->primaryKey;
			if (!empty($primaryKey)) {
				$criteria->order = $primaryKey.' desc';
			} else {
				$columns = $name->attributeNames();
				$criteria->order = $columns[0].' desc';
			}
			$data = new CActiveDataProvider ( get_class($name), array (
					'criteria' => $criteria,
						
					'pagination' => array (
							'pageSize' => $pageSize,
							'currentPage' => $currentPage
					)
			) );
		
			echo "<!--\n";
			foreach($data->getData() as $value){
				// print_r($value->attributes);
				if (! empty ( $value->attributes ) && is_array ( $value->attributes )) {
					$value->attributes = array_map ( 'addslashes', $value->attributes );
					if (! empty ( $value->attributes )) {
						$sql = Base::multiInsert ( $name->tableName (), $value->attributes );
						$sql = preg_replace ( '/insert\s*?into/i', 'REPLACE INTO', $sql );
						echo $sql . ";\n";
					}
				}
			}
			echo "\n<BR>//-->";
		}
	}
}

?>